﻿Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data


Public Class class_admin

    Private _Log As String
    Public Property log() As String
        Get
            Return _Log
        End Get
        Set(ByVal value As String)
            _Log = value
        End Set
    End Property



    Public Sub Guardar_Evaluacion(ByVal modo As String, ByVal descripcion As String)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_mantenimiento_evaluacion")
            DB.AddInParameter(cmd, "@i_nombre", DbType.String, descripcion)
            DB.AddInParameter(cmd, "@i_modo", DbType.String, modo)
            DB.AddOutParameter(cmd, "@ERROR", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "@ERROR")
            MsgBox(MsgBoxStyle.OkOnly)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub


    Public Sub Ingresar_materia(ByVal modo As String, ByVal codigo As String, ByVal nombre As String, ByVal estado As String, ByVal errore As Integer)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_materias")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "codigo", DbType.String, codigo)
            DB.AddInParameter(cmd, "nombre", DbType.String, nombre)
            DB.AddInParameter(cmd, "estado", DbType.String, estado)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub Modificar_materias(ByVal modo As String, ByVal id As Integer, ByVal nombre As String, ByVal estado As String, ByVal codigo As Integer)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_materias")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "id_materia", DbType.String, id)
            DB.AddInParameter(cmd, "codigo", DbType.String, codigo)
            DB.AddInParameter(cmd, "nombre", DbType.String, nombre)
            DB.AddInParameter(cmd, "estado", DbType.String, estado)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub Ingresar_aula(ByVal modo As String, ByVal numero As Integer, ByVal descripcion As String, ByVal estado As String, ByVal capacidad As Integer)

        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_aulas")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "numero", DbType.String, numero)
            DB.AddInParameter(cmd, "descripcion", DbType.String, descripcion)
            DB.AddInParameter(cmd, "estado", DbType.String, estado)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub Insertar_Rol(ByVal modo As String, ByVal nombre As String, ByVal descripcion As String, ByVal errore As Integer)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_rol")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "id_rol", DbType.Int16, DBNull.Value)
            DB.AddInParameter(cmd, "nombre", DbType.String, nombre)
            DB.AddInParameter(cmd, "descripcion", DbType.String, descripcion)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub Modificar_Rol(ByVal modo As String, ByVal id_rol As Integer, ByVal nombre As String, ByVal descripcion As String, ByVal errore As Integer)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_rol")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "id_rol", DbType.Int16, id_rol)
            DB.AddInParameter(cmd, "nombre", DbType.String, nombre)
            DB.AddInParameter(cmd, "descripcion", DbType.String, descripcion)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

    Public Sub Eliminar_Rol(ByVal modo As String, ByVal id_rol As Integer, ByVal errore As Integer)
        Try
            Dim DB As Database = DatabaseFactory.CreateDatabase("ASI2UFG")
            Dim cmd As Common.DbCommand = DB.GetStoredProcCommand("sp_rol")
            DB.AddInParameter(cmd, "modo", DbType.String, modo)
            DB.AddInParameter(cmd, "id_rol", DbType.Int16, id_rol)
            DB.AddInParameter(cmd, "nombre", DbType.String, DBNull.Value)
            DB.AddInParameter(cmd, "descripcion", DbType.String, DBNull.Value)
            DB.AddOutParameter(cmd, "error", DbType.Int16, 5)
            DB.ExecuteNonQuery(cmd)
            _Log = DB.GetParameterValue(cmd, "error")

        Catch exc As SqlException
            MsgBox(exc.Message, MsgBoxStyle.Critical)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub

End Class
